package wei.xinya.core.string;

class StringBufferTest {
    private final StringBuffer contents = new StringBuffer();

    void log(String message) {
        contents.append(System.currentTimeMillis());
        contents.append("; ");
        contents.append(Thread.currentThread().getName());
        for (int i = 0; i < 5; i++) {
            contents.append(i);
            contents.append(message);
            contents.append("\n");
        }
    }

    void getContents() {
        System.out.println(contents);
    }
}

class RunThread extends Thread {
    String message;
    StringBufferTest buffer;

    public RunThread(StringBufferTest buffer, String message) {
        this.buffer = buffer;
        this.message = message;
    }

    public void run() {
//        while (true) {
            buffer.log(message);
            buffer.getContents();
//        }
    }

    public static void main(String[] args) {
        StringBufferTest ss = new StringBufferTest();
        new RunThread(ss, "love").start();
        new RunThread(ss, "make").start();
        new RunThread(ss, "you").start();
    }
}
